package com.quick;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;

/**
 * @ClassName FutureTaskTest
 * @Description TODO
 * @Author wangxin332
 * @Date 2018/9/26 下午3:50
 * @Version 1.0
 **/
public class FutureTaskTest {
	public static void main(String[] args) {
		FutureTask<Integer> task = new FutureTask<Integer>(new Callable<Integer>() {
			@Override
			public Integer call() throws Exception {
				int i = 0;
				for (; i < 10; i++) {
					try {
						System.out.println(Thread.currentThread().getName() + "_"
								+ i);
						Thread.sleep(500);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
				return i;
			}
		}){
			@Override
			protected void done() {
				try {
					System.out.println("future.done():" + get());
				}catch (Exception e){

				}
			}
		};
		ExecutorService executor = Executors.newCachedThreadPool();
		executor.execute(task);
	}
}
